#ifndef PACKETPARSER_H
#define PACKETPARSER_H

#include "dllspec.h"

#include <SFML/Network.hpp>

// Abstract class that package processors (CLient and server) should derive from and implement specific package handling.
class DLL_EXPORT PacketParser
{
	public:
		void HandlePacket(
			sf::IPAddress sender,
			unsigned short port,
			sf::Packet& packet);

		sf::Packet CreatePacketHeader(
			sf::Uint32 id,
			sf::Uint8 type);

		int numPacketsReceived;
		int lastNumPacketsReceived;
		float avgNumPackets;

	protected:
		PacketParser();
		virtual ~PacketParser();

		virtual void HandleAdminPacket(
			sf::IPAddress sender,
			unsigned short port,
			sf::Uint32 clientID,
			sf::Packet& packet) = 0;

		virtual void HandleConnectionPacket(
			sf::IPAddress sender,
			unsigned short port,
			sf::Uint32 clientID,
			sf::Packet& packet) = 0;

		virtual void HandleWorldUpdatePacket(
			sf::IPAddress sender,
			unsigned short port,
			sf::Uint32 clientID,
			sf::Packet& packet) = 0;

		std::string PacketToString(sf::Packet packet);

	private:
		sf::Uint32 ExtractIDFromPacket(sf::Packet& packet);
};

#endif // PACKETPARSER_H
